using System;
using System.Text;
using System.Data;
using System.Data.Sql;
using System.Collections.Generic;
using System.Reflection;

namespace DocumentManagement
{
  /// <summary>
  /// Temployees Data Object Class
  /// </summary>
  public partial class DOTemployees
  {
    #region Class Constant declarations
    		/// <summary>
		/// The Table Column for the Temployees FEMPNO
		/// </summary>
		public const string RowFEMPNO = "FEMPNO";

		/// <summary>
		/// The Table Column for the Temployees FEMPFNAME
		/// </summary>
		public const string RowFEMPFNAME = "FEMPFNAME";

		/// <summary>
		/// The Table Column for the Temployees FEMPLNAME
		/// </summary>
		public const string RowFEMPLNAME = "FEMPLNAME";

		/// <summary>
		/// The Table Column for the Temployees FEMPDEPART
		/// </summary>
		public const string RowFEMPDEPART = "FEMPDEPART";

		/// <summary>
		/// The Table Column for the Temployees FEMPEMAIL
		/// </summary>
		public const string RowFEMPEMAIL = "FEMPEMAIL";

		/// <summary>
		/// The Table Column for the Temployees FEMPGROUP
		/// </summary>
		public const string RowFEMPGROUP = "FEMPGROUP";


#region Stored Procedures
private const string m_StoredProcedureConstCreate = "spTemployees_Create";
private const string m_StoredProcedureConstDelete = "spTemployees_Delete";
private const string m_StoredProcedureConstRetrieve = "spTemployees_Retrieve";
private const string m_StoredProcedureConstRetrieveall = "spTemployees_Retrieveall";
private const string m_StoredProcedureConstUpdate = "spTemployees_Update";
#endregion
    
    
    #endregion

    #region Class Variable declarations
    	#region DO Variables
		private string m_FEMPNO;
		private string m_FEMPFNAME;
		private string m_FEMPLNAME;
		private string m_FEMPDEPART;
		private string m_FEMPEMAIL;
		private string m_FEMPGROUP;
	#endregion
    
	#region Default Variables
	private SQLDataObject sqlData;
	private List<DOTemployees> m_Temployeess = new List<DOTemployees>();
	#endregion
	
    #endregion

    #region Class Constructors & Destructors
    /// <summary>
    /// Class Constructor
    /// </summary>
    public DOTemployees() { }
    #endregion

    #region Class Properties
    #region DO Properties
		/// <summary>
		/// FEMPNO
		/// </summary>
		/// <remarks>
		/// This property contains the Temployees FEMPNO
		/// </remarks>
		public string FEMPNO
		{
			get { return (this.m_FEMPNO); }
			set { this.m_FEMPNO = value; }
		}

		/// <summary>
		/// FEMPFNAME
		/// </summary>
		/// <remarks>
		/// This property contains the Temployees FEMPFNAME
		/// </remarks>
		public string FEMPFNAME
		{
			get { return (this.m_FEMPFNAME); }
			set { this.m_FEMPFNAME = value; }
		}

		/// <summary>
		/// FEMPLNAME
		/// </summary>
		/// <remarks>
		/// This property contains the Temployees FEMPLNAME
		/// </remarks>
		public string FEMPLNAME
		{
			get { return (this.m_FEMPLNAME); }
			set { this.m_FEMPLNAME = value; }
		}

		/// <summary>
		/// FEMPDEPART
		/// </summary>
		/// <remarks>
		/// This property contains the Temployees FEMPDEPART
		/// </remarks>
		public string FEMPDEPART
		{
			get { return (this.m_FEMPDEPART); }
			set { this.m_FEMPDEPART = value; }
		}

		/// <summary>
		/// FEMPEMAIL
		/// </summary>
		/// <remarks>
		/// This property contains the Temployees FEMPEMAIL
		/// </remarks>
		public string FEMPEMAIL
		{
			get { return (this.m_FEMPEMAIL); }
			set { this.m_FEMPEMAIL = value; }
		}

		/// <summary>
		/// FEMPGROUP
		/// </summary>
		/// <remarks>
		/// This property contains the Temployees FEMPGROUP
		/// </remarks>
		public string FEMPGROUP
		{
			get { return (this.m_FEMPGROUP); }
			set { this.m_FEMPGROUP = value; }
		}
		#endregion
    
	#region Default Properties
	public List<DOTemployees> Temployeess
	{
	  get { return m_Temployeess; }
	  set { m_Temployeess = value; }
	}    
	#endregion
	
    #endregion

    #region Class Methods
    public DataSet Retrieve()
    {
      DataSet returnDS = new DataSet();
      sqlData = new SQLDataObject();
      sqlData.ExecuteDataSetSQL(m_StoredProcedureConstRetrieve + " @" + RowFEMPNO + "=" + this.FEMPNO);
      return returnDS;
    }

    public bool RetrieveAll()
    {
      sqlData = new SQLDataObject();
      DataSet resultDS = sqlData.ExecuteDataSetSQL(m_StoredProcedureConstRetrieveall);
      return SetClassPropertiesListFromDataSet(resultDS);
    }

    public bool Create()
    {
      bool success = false;
      string sVariables = "";
      sqlData = new SQLDataObject();

      Type type = this.GetType();
      PropertyInfo[] propInfo = type.GetProperties();

      for (int i = 0; i < propInfo.Length; i++)
      {
        if (propInfo[i].PropertyType.Name.IndexOf("List") == -1)
        {
          sVariables += "@" + propInfo[i].Name + " = ";
          if (propInfo[i].PropertyType.Name == "String")
            sVariables += "'" + propInfo[i].GetValue(this, null) + "', ";
          else
            sVariables += propInfo[i].GetValue(this, null) + ", ";
        }
      }

      success = sqlData.ExecuteNonQuerySQL(m_StoredProcedureConstCreate + " " + sVariables.Substring(0, sVariables.Length - 2));

      return success;
    }

    public bool Update()
    {
      bool success = false;
      string sVariables = "";
      sqlData = new SQLDataObject();

      Type type = this.GetType();
      PropertyInfo[] propInfo = type.GetProperties();

      for (int i = 0; i < propInfo.Length; i++)
      {
        if (propInfo[i].PropertyType.Name.IndexOf("List") == -1)
        {
          sVariables += "@" + propInfo[i].Name + " = ";
          if (propInfo[i].PropertyType.Name == "String")
            sVariables += "'" + propInfo[i].GetValue(this, null) + "', ";
          else
            sVariables += propInfo[i].GetValue(this, null) + ", ";
        }
      }

      success = sqlData.ExecuteNonQuerySQL(m_StoredProcedureConstUpdate + " " + sVariables.Substring(0, sVariables.Length - 2));

      return success;
    }

    private bool SetClassPropertiesFromDataSet(DataSet resultDS)
    {
      bool success = false;
      if (resultDS.Tables[0] != null)
      {
        if (resultDS.Tables[0].Rows.Count > 0)
        {
          foreach (DataRow dr in resultDS.Tables[0].Rows)
          {
					if (dr[RowFEMPNO].ToString() != "")
			this.FEMPNO = dr[RowFEMPNO].ToString();

		if (dr[RowFEMPFNAME].ToString() != "")
			this.FEMPFNAME = dr[RowFEMPFNAME].ToString();

		if (dr[RowFEMPLNAME].ToString() != "")
			this.FEMPLNAME = dr[RowFEMPLNAME].ToString();

		if (dr[RowFEMPDEPART].ToString() != "")
			this.FEMPDEPART = dr[RowFEMPDEPART].ToString();

		if (dr[RowFEMPEMAIL].ToString() != "")
			this.FEMPEMAIL = dr[RowFEMPEMAIL].ToString();

		if (dr[RowFEMPGROUP].ToString() != "")
			this.FEMPGROUP = dr[RowFEMPGROUP].ToString();
          }
          success = true;
        }
      }
      return success;
    }

    private bool SetClassPropertiesListFromDataSet(DataSet resultDS)
    {
      bool success = false;
      if (resultDS.Tables[0] != null)
      {
        if (resultDS.Tables[0].Rows.Count > 0)
        {
          foreach (DataRow dr in resultDS.Tables[0].Rows)
          {
            DOTemployees Temployees = new DOTemployees();
			
					if (dr[RowFEMPNO].ToString() != "")
			Temployees.FEMPNO = dr[RowFEMPNO].ToString();

		if (dr[RowFEMPFNAME].ToString() != "")
			Temployees.FEMPFNAME = dr[RowFEMPFNAME].ToString();

		if (dr[RowFEMPLNAME].ToString() != "")
			Temployees.FEMPLNAME = dr[RowFEMPLNAME].ToString();

		if (dr[RowFEMPDEPART].ToString() != "")
			Temployees.FEMPDEPART = dr[RowFEMPDEPART].ToString();

		if (dr[RowFEMPEMAIL].ToString() != "")
			Temployees.FEMPEMAIL = dr[RowFEMPEMAIL].ToString();

		if (dr[RowFEMPGROUP].ToString() != "")
			Temployees.FEMPGROUP = dr[RowFEMPGROUP].ToString();

            this.Temployeess.Add(Temployees);
          }
          success = true;
        }
      }
      return success;
    }
    #endregion

    #region Class Support Methods
    #endregion
  }
}
